<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0px;
            margin: 0px;
        }
        .parent {
            background: #ff8787;
            /* position: relative; */
            /* 5.通过给父容器设置flex弹性布局解决 */
            display: flex;
            /* justify-content: center; */
        }
        
        .child {
            /* 子元素有宽度的设定 */
            width: 300px;
            height: 300px;
            background-color: aquamarine;
            /* 1. 设置margin完成居中操作 */
            /* margin: 0 auto; */
            
            /* 2.设置相对定位 + margin-left 来实现 */
            /* position: relative;
            left : 50%;
            margin-left: -150px; */

            /*  3.子绝父相 + 平移*/
            /* position: absolute;
            left: 50%;
            transform: translateX(-50%); */

            /* 4.子绝父相 + left + right + margin */
            /* position: absolute;
            left: 0;
            right: 0;
            margin: 0 auto; */

            /* 5. 父容器flex + 子容器margin*/
            /* margin: 0 auto; */
        }
    </style>
</head>

<body>
    <div class="parent">
        <div class="child"></div>
    </div>
</body>

</html>